package com.lc.luzhengtang.adapter;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.activity.OrderDetailActivity2;
import com.lc.luzhengtang.activity.WuliuActivity;
import com.lc.luzhengtang.bean.OrderListBean;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.ArrayList;
import java.util.List;

import static com.lc.luzhengtang.R.id.btn_tuikuan;
import static com.lc.luzhengtang.util.CommonUtils.getResources;

/**
 * https://github.com/CymChad/BaseRecyclerViewAdapterHelper
 */
public class SectionOrderListAdapter extends BaseQuickAdapter<OrderListBean.DataBean, BaseViewHolder> implements View.OnClickListener {

    RecyclerView recyclerView;
    SectionItem_List_Adapter sectionItemAdapter;
    List<OrderListBean.DataBean> dataBeen;
    //查看物流的
    Button btn_wuliu;

    Button btn_submit_shouhuo;

    //去评价的界面
    Button btn_pignjia;


    List<OrderListBean.DataBean.OrderslistBean> orderslistBeanList = new ArrayList<>();


    private OnCommentClickListener onCommentClickListener;


    List<Integer> stringList = new ArrayList<>();

    public void setOnCommentClickListener(OnCommentClickListener onCommentClickListener) {
        this.onCommentClickListener = onCommentClickListener;
    }

    public SectionOrderListAdapter(List<OrderListBean.DataBean> data) {
        super(R.layout.item_order, data);
        this.dataBeen = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, final OrderListBean.DataBean item) {
        ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) helper.convertView);
        recyclerView = helper.getView(R.id.recycle_personal_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        sectionItemAdapter = new SectionItem_List_Adapter(item.getOrderslist());
        View view = helper.getConvertView();

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();

                intent.putExtra("ordersn", item.getOrdersn());
                intent.putExtra("status", item.getStatus() + "");
                intent.putExtra("order_id", item.getId() + "");

                intent.setClass(mContext, OrderDetailActivity2.class);
                mContext.startActivity(intent);
            }
        });
        for (int i = 0; i < item.getOrderslist().size(); i++) {
            stringList.add(item.getOrderslist().get(i).getOrderslist_id());
        }

//        bundle.putIntegerArrayList(EvaluateActivity.KEY_IDS, idList);


        helper.addOnClickListener(R.id.text_cancel_order);
        sectionItemAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent();
                intent.putExtra("ordersn", item.getOrdersn());
                intent.putExtra("status", item.getStatus() + "");
                intent.putExtra("order_id", item.getId() + "");
                intent.putExtra("weburl", item.getUrl());
                intent.putIntegerArrayListExtra("stringList", (ArrayList<Integer>) stringList);
                intent.setClass(mContext, OrderDetailActivity2.class);
                mContext.startActivity(intent);

            }
        });

        helper.addOnClickListener(R.id.btn_cancelorder);
        helper.addOnClickListener(R.id.btn_pay_detail);
/*
        if (item.getStatus() == 1 && item.getPaytype().equals("4")) {
            helper.setText(R.id.text_status_fukuan, "待付款");
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, true);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, true);
        } else if (item.getStatus() == 1 || item.getPaytype().equals("2") || item.getPaytype().equals("3") || item.getPaytype().equals("1")) {
            helper.setText(R.id.text_status_fukuan, "待付款");
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, true);
            //去付款
            helper.setVisible(R.id.btn_pay, true);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);

        } */

        if (item.getStatus() == 1 && item.getPaytype().equals("4")) {
            helper.setText(R.id.text_status_fukuan, "待付款");
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, true);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, true);
        } else if (item.getStatus() == 1 && item.getPaytype().equals("1")) {
            helper.setText(R.id.text_status_fukuan, "待付款");
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, true);
            //去付款
            helper.setVisible(R.id.btn_pay, true);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 1 && item.getPaytype().equals("3")) {
            helper.setText(R.id.text_status_fukuan, "待付款");
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, true);
            //去付款
            helper.setVisible(R.id.btn_pay, true);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 1 && item.getPaytype().equals("2")) {
            helper.setText(R.id.text_status_fukuan, "待付款");
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, true);
            //去付款
            helper.setVisible(R.id.btn_pay, true);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 1 && item.getPaytype().equals("0")) {
            helper.setText(R.id.text_status_fukuan, "待付款");
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, true);
            //去付款
            helper.setVisible(R.id.btn_pay, true);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 2) {
            helper.setText(R.id.text_status_fukuan, "买家已付款，待卖家发货");
            helper.setTextColor(R.id.text_status_fukuan, mContext.getResources().getColor(R.color.text_color_order));
            helper.setVisible(R.id.btn_tuikuan, true);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 3) {
            helper.setText(R.id.text_status_fukuan, "已发货");
            helper.setTextColor(R.id.text_status_fukuan, getResources().getColor(R.color.classfiy_select));
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, true);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, true);

            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 4) {


//            helper.setVisible(R.id.btn_submit_shouhuo, false);
            helper.setText(R.id.text_status_fukuan, "已收货");


            helper.setTextColor(R.id.text_status_fukuan, getResources().getColor(R.color.classfiy_select));
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, true);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);
            helper.setVisible(R.id.btn_pay_detail, false);
//            helper.setVisible(R.id.text_cancel_order, true);
            helper.setVisible(R.id.text_cancel_order, false);

            helper.setVisible(R.id.text_status_fukuan, false);
        } else if (item.getStatus() == 5) {
            helper.setText(R.id.text_status_fukuan, "交易成功");
            helper.setTextColor(R.id.text_status_fukuan, getResources().getColor(R.color.classfiy_select));
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);
//            helper.setVisible(R.id.layout_tuikuan, false);
            helper.setVisible(R.id.btn_pay_detail, true);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 6) {
            helper.setVisible(R.id.layout_tuikuan, false);

            helper.setVisible(R.id.btn_pay_detail, false);
        } else if (item.getStatus() == 7) {
            helper.setVisible(R.id.layout_tuikuan, true);
            helper.setText(R.id.text_status_fukuan, "交易成功");
            helper.setVisible(R.id.btn_wuliu, true);
            helper.setText(R.id.btn_wuliu, "查看物流");
            helper.setVisible(R.id.btn_submit_shouhuo, true);
            helper.setText(R.id.text_status_fukuan, "已收货");
            helper.setText(R.id.text_status_fukuan, "已申请退货");

            helper.setTextColor(R.id.text_status_fukuan, getResources().getColor(R.color.classfiy_select));
            //退款
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, true);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, true);
            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 8) {
            helper.setText(R.id.text_status_fukuan, "买家已付款，待卖家发货");
            helper.setTextColor(R.id.text_status_fukuan, mContext.getResources().getColor(R.color.text_color_order));
            helper.setVisible(R.id.btn_tuikuan, true);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);
            // 查看订单
            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 9) {
            helper.setVisible(R.id.layout_tuikuan, false);
            //查看订单
            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 10) {
//            btn_wuliu 可见
            helper.setText(R.id.text_status_fukuan, "退货中");
            helper.setTextColor(R.id.text_status_fukuan, mContext.getResources().getColor(R.color.text_color_order));
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, true);
            //查看订单
            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 11) {
            helper.setText(R.id.text_status_fukuan, "已退款");
            helper.setTextColor(R.id.text_status_fukuan, mContext.getResources().getColor(R.color.text_color_order));
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);
            helper.setVisible(R.id.layout_tuikuan, false);
            //查看订单
            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 12) {
            helper.setText(R.id.text_status_fukuan, "已退货");
            helper.setTextColor(R.id.text_status_fukuan, mContext.getResources().getColor(R.color.text_color_order));
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);
            helper.setVisible(R.id.layout_tuikuan, false);
            //查看订单
            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 13) {
            helper.setText(R.id.text_status_fukuan, "拒绝退款");
            helper.setTextColor(R.id.text_status_fukuan, mContext.getResources().getColor(R.color.text_color_order));
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);
            helper.setVisible(R.id.layout_tuikuan, false);
            //查看订单
            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else if (item.getStatus() == 14) {
            helper.setText(R.id.text_status_fukuan, "拒绝退货");
            helper.setTextColor(R.id.text_status_fukuan, mContext.getResources().getColor(R.color.text_color_order));
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);
            helper.setVisible(R.id.layout_tuikuan, false);
            //查看订单
            helper.setVisible(R.id.btn_pay_detail, false);
            helper.setVisible(R.id.text_cancel_order, false);
        } else {
            helper.setVisible(R.id.layout_tuikuan, false);
            helper.setVisible(R.id.btn_tuikuan, false);
            //取消订单
            helper.setVisible(R.id.btn_cancelorder, false);
            //去付款
            helper.setVisible(R.id.btn_pay, false);
            //评价
            helper.setVisible(R.id.btn_pignjia, false);
            //退款
            //确认收货
            helper.setVisible(R.id.btn_submit_shouhuo, false);
            //物流跟踪btn_wuliu
            helper.setVisible(R.id.btn_wuliu, false);
            helper.setVisible(R.id.text_cancel_order, false);

        }

        if (item != null) {
            recyclerView.setAdapter(sectionItemAdapter);
        }


        btn_wuliu = helper.getView(R.id.btn_wuliu);
        btn_wuliu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent();

                intent.putExtra("url", item.getUrl());
                intent.setClass(mContext, WuliuActivity.class);
                mContext.startActivity(intent);
            }
        });


        btn_submit_shouhuo = helper.getView(R.id.btn_submit_shouhuo);
        helper.addOnClickListener(R.id.btn_submit_shouhuo);

        helper.addOnClickListener(R.id.btn_cancelorder);
        //去付款
        helper.addOnClickListener(R.id.btn_pay);
//申请退款
        helper.addOnClickListener(btn_tuikuan);

        btn_pignjia = helper.getView(R.id.btn_pignjia);
        btn_pignjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (onCommentClickListener != null) {
                    onCommentClickListener.onCommentClick(item);
                }

            }
        });

    }

    public interface OnCommentClickListener {
        void onCommentClick(OrderListBean.DataBean dataBean);
    }

    public interface OnCommentClickListener2 {
        void onCommentClick(OrderListBean.DataBean dataBean);
    }

    @Override
    public void onClick(View v) {

    }
}
